/*
 * $Id: CfgCodeDetails.java,v 1.11 2009/09/15 19:12:27 navdeep_mahajan Exp $
 *
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 *
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */

package com.ge.healthcare.autosc.common.database.pojo;

import com.ge.healthcare.autosc.common.ASCUtil;

/**
 * CfgCodeDetails entity.
 * 
 * @author MyEclipse Persistence Tools
 */
public class CfgCodeDetails extends AbstractCfgCodeDetails implements
		java.io.Serializable {
	/**
	 * Eclipse generated
	 */
	private static final long serialVersionUID = 5216623443724013792L;

	public static final String TABLE_NAME = "com.ge.healthcare.autosc.common.database.pojo.CfgCodeDetails";

	public static final String COL_CODE_ID = "codeId";
	public static final String COL_CODE_NAME = "codeName";
	public static final String COL_CODE_DESC = "codeDesc";

	public static final Character SUCCESS_CODE_GROUP = Character.valueOf('S');
	public static final Character RETRY_CODE_GROUP = Character.valueOf('R');
	public static final Character FAILURE_CODE_GROUP = Character.valueOf('F');
	public static final Character PROCESSING_CODE_GROUP = Character
			.valueOf('P');

	public static final String GROUP_DESC_SUCCESS = "success";
	public static final String GROUP_DESC_RETRY = "retry";
	public static final String GROUP_DESC_FAILURE = "failure";
	public static final String GROUP_DESC_PROCESSING = "processing";
	public static final String GROUP_DESC_UNKNOWN = "processing";
	public static final String GROUP_DESC_UNDEFINED = "processing";

	// Constructors

	/** default constructor */
	public CfgCodeDetails() {
	}

	public CfgCodeDetails(String name, String desc, char group) {
		this.setCodeName(name);
		this.setCodeDesc(desc);
		this.setCodeGroup(group);
	}

	public String toString() {
		StringBuffer str = new StringBuffer();
		str.append("{Code Id=").append(this.getCodeId()).append("},");
		str.append("{Code Namee=").append(this.getCodeName()).append("},");
		str.append("{codeDesc=").append(this.getCodeDesc()).append("},");
		str.append("{codeGroup=").append(this.getCodeGroup()).append("}");
		return str.toString();
	}

	public static boolean isSuccess(CfgCodeDetails code) {
		if (ASCUtil.isNullOrEmptyObject(code)) {
			return false;
		} else {
			return isSuccess(code.getCodeGroup());
		}
	}

	public static boolean isFailed(CfgCodeDetails code) {
		if (ASCUtil.isNullOrEmptyObject(code)) {
			return false;
		} else {
			return isFailed(code.getCodeGroup());
		}
	}

	public boolean isFailed() {
		return isFailed(this.getCodeGroup());
	}

	public boolean isComplete() {
		if (isFailed(this.getCodeGroup()) || isSuccess(this.getCodeGroup())) {
			return true;
		}
		return false;
	}

	public boolean isSuccess() {
		return isSuccess(this.getCodeGroup());
	}

	public static boolean isSuccess(String code) {
		if (ASCUtil.isNullOrEmpty(code)) {
			return false;
		} else {
			return isSuccess(code.toCharArray()[0]);
		}
	}

	public static boolean isFailed(String code) {
		if (ASCUtil.isNullOrEmpty(code)) {
			return false;
		} else {
			return isFailed(code.toCharArray()[0]);
		}
	}

	public static boolean isSuccess(Character code) {
		if (ASCUtil.isNullOrEmptyObject(code)) {
			return false;
		} else if (CfgCodeDetails.SUCCESS_CODE_GROUP.equals(code)) {
			return true;
		}
		return false;
	}

	public static boolean isFailed(Character code) {
		if (ASCUtil.isNullOrEmptyObject(code)) {
			return false;
		} else if (CfgCodeDetails.FAILURE_CODE_GROUP.equals(code)) {
			return true;
		}
		return false;
	}

	/**
	 * This returns a long description of the code group value
	 * 
	 * @return
	 */
	public String getCodeGroupLong() {
		Character codeGroup = getCodeGroup();
		String code = GROUP_DESC_UNKNOWN;
		if (ASCUtil.isNullOrEmptyObject(codeGroup)) {
			code = GROUP_DESC_UNDEFINED;
		} else if (SUCCESS_CODE_GROUP.equals(codeGroup)) {
			code = GROUP_DESC_SUCCESS;
		} else if (RETRY_CODE_GROUP.equals(codeGroup)) {
			code = GROUP_DESC_RETRY;
		} else if (FAILURE_CODE_GROUP.equals(codeGroup)) {
			code = GROUP_DESC_FAILURE;
		} else if (PROCESSING_CODE_GROUP.equals(codeGroup)) {
			code = GROUP_DESC_PROCESSING;
		}
		return code;
	}
}
